Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up error handling to have less unexpected errors #529

Merged
merged 3 commits into from
Dec 16, 2024

Conversation

ecooper
Copy link
Contributor

@ecooper ecooper commented Dec 13, 2024

Problem

We have a few inconsistencies in error handling:

  • Account API failures were very verbose and almost always "unexpected errors" even in cases you'd expect them, such as:
    • invalid inputs: like bad region groups
    • 404s: like missing databases
  • Common Fauna errors could sneak through and be very confusing. The most notable of this is if you have a bad --secret
  • Authentication errors in general weren't being consistently caught and displayed.

Solution

This PR does a few things, but it most notably commits to using the errors defined in errors.mjs in our lib code. Through adding new exceptions and common patterns to convert 3rd party errors to things we expect, we can get rid of most unexpected errors.

  • New exceptions: Add AuthenticationError and AuthorizationError. The 401 case has a default message to remove the inconsistent ones we have already.
  • xxxxToCommandError helpers: Simplified the existing throwForError function to just be a translation layer to catch the common error types across our dependencies.

Result

Authentication errors and 4XX errors display consistently across the account, v4, v10, and schema APIs.

Testing

Add unit tests for the error mappings. Updated existing error tests.

Comment on lines -38 to +48
// Schema push requires fsl locally...we need to accommodate for that, but for now, we'll just skip it
if (command === "schema push") {
return;
}
container.resolve("fetch").rejects(new TypeError("fetch failed"));
container.resolve("gatherFSL").resolves([
{
name: "test.fsl",
content: "collection Test { name: String }",
},
]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10/10, fun with DI testing

@mwilde345 mwilde345 merged commit aa22fac into v3 Dec 16, 2024
4 checks passed
@mwilde345 mwilde345 deleted the v3-common-errors branch December 16, 2024 16:56
@mwilde345 mwilde345 mentioned this pull request Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants